home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / clib / calloc.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  1KB  |  80 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: calloc.c,v 1.1 1996/10/19 17:44:25 aros Exp $
  4.  
  5.     Desc: ANSI C function calloc()
  6.     Lang: english
  7. */
  8. #include <exec/types.h>
  9.  
  10. /*****************************************************************************
  11.  
  12.     NAME */
  13.     #include <sys/types.h>
  14.     #include <memory.h>
  15.  
  16.     void * calloc (
  17.  
  18. /*  SYNOPSIS */
  19.     size_t count,
  20.     size_t size)
  21.  
  22. /*  FUNCTION
  23.     Allocate size bytes of memory, clears the memory (sets all bytes to
  24.     0) and returns the address of the first byte.
  25.  
  26.     INPUTS
  27.     count - How many time size
  28.     size - How much memory to allocate.
  29.  
  30.     RESULT
  31.     A pointer to the allocated memory or NULL. If you don't need the
  32.     memory anymore, you can pass this pointer to free(). If you don't,
  33.     the memory will be freed for you when the application exits.
  34.  
  35.     NOTES
  36.  
  37.     EXAMPLE
  38.  
  39.     BUGS
  40.  
  41.     SEE ALSO
  42.     free(), malloc()
  43.  
  44.     INTERNALS
  45.  
  46.     HISTORY
  47.     24-12-95    digulla created
  48.  
  49. ******************************************************************************/
  50. {
  51.     ULONG * mem;
  52.  
  53.     /* Allocate the memory */
  54.     mem = malloc (size*count);
  55.  
  56.     if (mem)
  57.     {
  58.     ULONG * ptr;
  59.  
  60.     ptr = mem;
  61.  
  62.     while (size > sizeof(ULONG))
  63.     {
  64.         *ptr++ = 0;
  65.         size -= sizeof (ULONG);
  66.     }
  67.  
  68.     if (size)
  69.     {
  70.         UBYTE * bptr = (UBYTE *)ptr;
  71.  
  72.         while (size --)
  73.         *bptr ++ = 0;
  74.     }
  75.     }
  76.  
  77.     return mem;
  78. } /* malloc */
  79.  
  80.